addpath('../lib');
addpath('../mockData');


A = importdata('data.dat');
data = A.data;
data = data - min(min(data));

wavesOrig = data(:, 1:1)';
timesOrig = A.colheaders(2:end);
timesOrig = strrep(timesOrig, 'min', '');
timesOrig = str2double(timesOrig);
data = data(:,2:end);

A = reshape(data(450:end, :),1,[]);
rms =  sqrt(mean(A.^2))
std(A)
mm = max(max(data))
rms / mm

wave = size(data, 1);
times = size(data, 2);

timeList = timesOrig;
waveList = wavesOrig;

R = 2;
niter = 500;
duomenys = data;

[W1 H1] = TNMF(duomenys, R, niter);

PlotW(waveList, W1, 'SpektrineInformacija');
PlotH(timeList, H1, 'TankiuKitimasLaike');

PlotMain(waveList,timeList, duomenys, 'PradiniaiDuomenys');
PlotMain(waveList,timeList, W1*H1, 'IsskirtosInformacijosBendrasVaizdas');
PlotMain(waveList, timeList, duomenys - W1*H1, 'skirtumasNuoPradiniuDuomenu', 'norm', 0);
disp('Finished');
